<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>search_and_add_store.js</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        
        <h1>
            search_and_add_store.js
        </h1>
        <ul class="files">
            
            <li>
                lib/assets/javascripts/ruiqu_app/store_friends/search_and_add_store.js
                
            </li>
            <li>Last modified: 2017-01-27 16:48:14 +0800</li>
        </ul>
    </div>

    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>jQuery(function($){</p>

<pre><code>$(&quot;a.btn.btn-primary.active&quot;).on(&quot;click&quot;, function(){
  BootstrapDialog.show({
          title: &#39;搜索好友&#39;,
          message: &quot;&lt;p class=&#39;text-warning&#39;&gt;*注: 为保证公司隐私，名称搜索只支持全称.&lt;/p&gt;&quot;
                  + &quot;搜索好友: &lt;input type=&#39;text&#39; class=&#39;js-search-store-friend&#39; placeholder= &#39;搜索公司名称或者系统id!&#39;&gt;&quot;,
          buttons: [{
              label: &#39;取消&#39;,
              action: function(dialog) {
                  dialog.close();
              }
          }, {
              label: &#39;确定&#39;,
              cssClass: &#39;btn-primary js-to-search-store-friend&#39;,
              action: function(dialog){
                  var searchValue = $(&quot;input.js-search-store-friend&quot;).val();
                  var q = {};
                  if (searchValue == &quot;&quot; || searchValue == null){
                    q[&#39;name_or_uid_eq&#39;] = 0
                    BootstrapDialog.alert(&#39;请输入要查询的公司!&#39;);
                    return false
                  }else {
                    q[&#39;name_or_uid_eq&#39;] = searchValue
                  }
                  $.ajax({
                    url: &#39;/api/stores&#39;,
                    method: &#39;get&#39;,
                    data: {q: q},
                    success: function(data){
                      if(data.status == true){
                        dialog.setMessage(
                          &quot;&lt;p class=&#39;text-warning&#39;&gt;*注: 为保证公司隐私，名称搜索只支持全称.&lt;/p&gt;&quot;
                         +&quot;搜索好友: &lt;input type=&#39;text&#39; value=&quot;+ searchValue
                         +&quot; class=&#39;js-search-store-friend&#39; placeholder= &#39;搜索公司名称或者系统id!&#39;&gt;&lt;/br&gt;&lt;/br&gt;&quot;
                         +&quot;&lt;span&gt;公司名称: &quot;+ data.name +&quot;&lt;/span&gt;&lt;/br&gt;&quot;
                         +&quot;&lt;span&gt;法人代码: &quot;+ data.legal_person + &quot;&lt;/span&gt;&lt;/br&gt;&quot;
                         +&quot;系统ID: &quot;+ data.uid + &quot;&lt;/br&gt;&lt;/br&gt;&quot;
                         +&quot;请输入验证信息:&lt;/br&gt;&quot;
                         +&quot;&lt;textarea class=&#39;form-control js-to-add-store-validation&#39; rows=&#39;3&#39;&gt;&lt;/textarea&gt;&quot;
                         +&quot;&lt;p&gt;&lt;button class=&#39;btn btn-mini btn-primary js-to-add-store-friend&#39; data-id=&quot;+ data.id +&quot; data-name=&quot;+ data.name +&quot; data-uid=&quot;+ data.uid +&quot; data-base-id=&quot;+ data.base_id +&quot; type=&#39;button&#39;&gt;&lt;i class=&#39;fa fa-user-plus&#39;&gt;&lt;/i&gt;添加好友&lt;/button&gt;&lt;/p&gt;&quot;
                       )
                      }else {
                        dialog.setMessage(
                          &quot;&lt;p class=&#39;text-warning&#39;&gt;*注: 为保证公司隐私，名称搜索只支持全称.&lt;/p&gt;&quot;
                         +&quot;搜索好友: &lt;input type=&#39;text&#39; value=&quot;+ searchValue
                         +&quot; class=&#39;js-search-store-friend&#39; placeholder= &#39;搜索公司名称或者系统id!&#39;&gt;&lt;/br&gt;&lt;/br&gt;&quot;

                         +&quot;不存在该友好公司&quot;
                        )
                      }
                    }
                  }) //ajax end
              }
          }]
      });
}) //click search store end

$(document).on(&quot;click&quot;, &quot;button.js-to-add-store-friend&quot;, function(){
  var validation = $(&quot;textarea.js-to-add-store-validation&quot;).val();
  var friendId = $(this).data(&quot;id&quot;);
  var baseId = $(this).data(&quot;base-id&quot;);
  var name = $(this).data(&quot;name&quot;);
  var uid = $(this).data(&quot;uid&quot;);
  var csrf = $(&quot;input#js-ruiqu-store-friend-index&quot;).val();

  $.ajax({
    url: &quot;/api/store_friends/friended&quot;,
    method: &quot;get&quot;,
    data: {friend_id: friendId},
    success: function(data){
      if (data.status == true) {
        BootstrapDialog.alert(&quot;已经是好友关系!&quot;);
      }else {
        $.ajax({
          url: &quot;/api/store_friends&quot;,
          method: &quot;post&quot;,
          headers: {
                    &#39;X-CSRF-Token&#39;: csrf
                  },
          data: {
                  friend_id: friendId,
                  validation: validation,
                  base_id: baseId,
                  name: name,
                  uid: uid
                },
          success: function(data){

          }
        }) //second ajax

      }
    }
  })

})</code></pre>

<p>})</p>

    </div>
  


  


  
  


  


  

  



  

    

    

    


    


    <!-- Methods -->
              </div>

    </div>
  </body>
</html>
